package com.gong.yuanma.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author GongChang
 * @version 1.0
 * @date 2021/6/18 0018 15:12
 */
public class BioServer {

    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(8080);
        while (true){
            Socket accept = socket.accept();

            new Thread(()->{
                try {
                    InputStream inputStream = accept.getInputStream();
                    byte[] bytes = new byte[1024*1024];
                    int len = 0;
                    while ((len = inputStream.read(bytes))!=-1){
                        String str = new String(bytes,0,len);
                        System.out.println(str);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
